<?php
    if (!isset($union_id)) $union_id="";
?>
<div class="row">
    <div class="col-xs-4">
        <select name="[union-num-name]" id="union_num" class="chosen-select form-control">
            {if condition="!empty($union_id)"}
            <option value="{$union_id}">{$union_id|get_union_name}【ID：{$union_id}】</option>
            {/if}
        </select>
    </div>
    <div class="col-xs-4">
        <input placeholder="请输入完整联盟商名称" type="text" id="union_sername" class="form-control" value="" />
    </div>
    <div class="col-xs-4">
        <button onclick="bus_ser()" type="button" class="btn btn-success btn-block">点击筛选</button>
    </div>

</div>
<script src="__PUBLIC__/vendors/select2/js/select2.min.js"></script>
<script type="application/javascript">
    $(function () {
        $("#union_num").select2({
            placeholder: "请选择所属联盟商，可先在右侧输入联盟商名称筛选",
            allowClear: true,
            width: "100%"
        });
    });
    function bus_ser(){
        var union_sername = $("#union_sername").val();
        if(union_sername==''){
            showErrorMessage('请先输入联盟商名称，再点击筛选');
            return false;
        }
        $.ajax({
            url: "{:url('Utils/queryUnion')}",
            type: 'POST', //GET
            async: true,    //或false,是否异步
            data: {
                title: union_sername
            },
            timeout: 5000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            success: function (data) {
                $("#union_num").empty();


                for (var i = 0; i < data.length; i++) {

                    $("#union_num").append("<option value='" + data[i].id + "'>" + data[i].title + "【ID："+data[i].id+"】</option>");

                }

            }
        })
    }
</script>